﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Fotobanka
{
    public partial class SpravaUzivateluVgalerii : System.Web.UI.Page
    {
        UserGalleriesManager ugm;
        protected void Page_Load(object sender, EventArgs e)
        {
            ugm = new UserGalleriesManager();
        }

        protected void addButton_Click(object sender, EventArgs e)
        {
            try {
                int id_u = Convert.ToInt32(lide.SelectedItem.Value.ToString());
                ugm.insertUserIntoGallery(id_u, Convert.ToInt32(Request.QueryString["id"]));
            }catch(Exception ex){
                Label1.Text = ex.Message;
            }
            GridView1.DataBind();
            lide.DataBind();
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                foreach (DataControlField dcf in ((GridView)sender).Columns)
                {
                    if (dcf.ToString() == "CommandField")
                    {
                        if (((CommandField)dcf).ShowDeleteButton == true)
                        {
                            e.Row.Cells[((GridView)sender).Columns.IndexOf(dcf)].Attributes
                            .Add("onclick", "return confirm(\"Opravdu chcete smazat?\")");
                        }
                    }
                }
            }
        }

        protected void OnDeleted(object sender, EventArgs e) {
            lide.DataBind();
        }
    }
}
